home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / mysql-test / t / func_group.test < prev    next >
Encoding:
Text File  |  2003-01-21  |  3.2 KB  |  101 lines  |  [TEXT/ttxt]

  1. #
  2. # simple test of all group functions
  3. #
  4.  
  5. create table t1 (grp int, a bigint unsigned, c char(10) not null);
  6. insert into t1 values (1,1,"a");
  7. insert into t1 values (2,2,"b");
  8. insert into t1 values (2,3,"c");
  9. insert into t1 values (3,4,"E");
  10. insert into t1 values (3,5,"C");
  11. insert into t1 values (3,6,"D");
  12.  
  13. # Test of MySQL field extension with and without matching records.
  14. select a,c,sum(a) from t1 group by a;
  15. select a,c,sum(a) from t1 where a > 10 group by a;
  16. select sum(a) from t1 where a > 10;
  17. select a from t1 order by rand(10);
  18. select distinct a from t1 order by rand(10);
  19. select count(distinct a),count(distinct grp) from t1;
  20. insert into t1 values (null,null,'');
  21. select count(distinct a),count(distinct grp) from t1;
  22.  
  23. select sum(a),count(a),avg(a),std(a),bit_or(a),bit_and(a),min(a),max(a),min(c),max(c) from t1;
  24. select grp, sum(a),count(a),avg(a),std(a),bit_or(a),bit_and(a),min(a),max(a),min(c),max(c) from t1 group by grp;
  25. select grp, sum(a)+count(a)+avg(a)+std(a)+bit_or(a)+bit_and(a)+min(a)+max(a)+min(c)+max(c) as sum from t1 group by grp;
  26.  
  27. create table t2 (grp int, a bigint unsigned, c char(10));
  28. insert into t2 select grp,max(a)+max(grp),max(c) from t1 group by grp;
  29. replace into t2 select grp, a, c from t1 limit 2,1;
  30. select * from t2;
  31.  
  32. drop table t1,t2;
  33.  
  34. #
  35. # Problem with std()
  36. #
  37.  
  38. CREATE TABLE t1 (id int(11),value1 float(10,2));
  39. INSERT INTO t1 VALUES (1,0.00),(1,1.00), (1,2.00), (2,10.00), (2,11.00), (2,12.00); 
  40. CREATE TABLE t2 (id int(11),name char(20)); 
  41. INSERT INTO t2 VALUES (1,'Set One'),(2,'Set Two'); 
  42. select id, avg(value1), std(value1) from t1 group by id;
  43. select name, avg(value1), std(value1) from t1, t2 where t1.id = t2.id group by t1.id;
  44. drop table t1,t2;
  45.  
  46. #
  47. # Test of bug in left join & avg
  48. #
  49.  
  50. create table t1 (id int not null);
  51. create table t2 (id int not null,rating int null);
  52. insert into t1 values(1),(2),(3);
  53. insert into t2 values(1, 3),(2, NULL),(2, NULL),(3, 2),(3, NULL);
  54. select t1.id, avg(rating) from t1 left join t2 on ( t1.id = t2.id ) group by t1.id;
  55. drop table t1,t2;
  56.  
  57. #
  58. # test of count
  59. #
  60. create table t1 (a smallint(6) primary key, c char(10), b text);
  61. INSERT INTO t1 VALUES (1,'1','1');
  62. INSERT INTO t1 VALUES (2,'2','2');
  63. INSERT INTO t1 VALUES (4,'4','4');
  64.  
  65. select count(*) from t1;
  66. select count(*) from t1 where a = 1;
  67. select count(*) from t1 where a = 100;
  68. select count(*) from t1 where a >= 10;
  69. select count(a) from t1 where a = 1;
  70. select count(a) from t1 where a = 100;
  71. select count(a) from t1 where a >= 10;
  72. select count(b) from t1 where b >= 2;
  73. select count(b) from t1 where b >= 10;
  74. select count(c) from t1 where c = 10;
  75. drop table t1;
  76.  
  77. #
  78. # Test of bug in COUNT(i)*(i+0)
  79. #
  80.  
  81. CREATE TABLE t1 (d DATETIME, i INT);
  82. INSERT INTO t1 VALUES (NOW(), 1);
  83. SELECT COUNT(i), i, COUNT(i)*i FROM t1 GROUP BY i;
  84. SELECT COUNT(i), (i+0), COUNT(i)*(i+0) FROM t1 GROUP BY i; 
  85. DROP TABLE t1;
  86.  
  87. #
  88. # Another SUM() problem with 3.23.2
  89. #
  90.  
  91. create table t1 (
  92.         num float(5,2),
  93.         user char(20)
  94. );
  95. insert into t1 values (10.3,'nem'),(20.53,'monty'),(30.23,'sinisa');
  96. insert into t1 values (30.13,'nem'),(20.98,'monty'),(10.45,'sinisa');
  97. insert into t1 values (5.2,'nem'),(8.64,'monty'),(11.12,'sinisa');
  98. select sum(num) from t1;
  99. select sum(num) from t1 group by user;
  100. drop table t1;
  101.